package time;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class m extends JFrame
{
	public m ()
	{
		ShowPointPlace p = new ShowPointPlace();
		setLayout(new BorderLayout());
		add(p);
	}
	static class ShowPointPlace extends JPanel
	{
		private String message1 = "Mouse point is not in the triangle";
		private String message2 = "Mouse point is in the triangle";
		private int x;
		private int y;
		Point pA = new Point(20,20);
		Point pB = new Point(100,100);
		Point pC = new Point(140,40);

	
		public ShowPointPlace()
		{
			
			addMouseMotionListener(new MouseMotionAdapter()
			{
				public void mouseMoved(MouseEvent e)
				{
					x = e.getX();
        			y = e.getY();
        			
        			repaint();
				}
			});
		}
		protected void paintComponent(Graphics g)
		{
			super.paintComponent(g);
			
			g.drawLine(20,20,100,100);
			g.drawLine(100,100,140,40);
			g.drawLine(140,40,20,20);
			
			
			if( (y>(1.0/6*x+100.0/6)) && (y<x) && (y<(-3.0/2*x+250)) )
			{ 
				g.drawString(message2,x,y);
			}
			else 
			{
				g.drawString(message1,x,y);
			}
		}		
	}
	public static void main(String []args)
	{
		m frame = new m ();
		frame.setTitle("Exercise 16.6");
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(300,150);
		frame.setVisible(true);
	}
}
